package com.example.redistest;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.params.ZParams;

import java.util.List;

public class RedisDemoString {
    public static void test1(Jedis jedis){
        jedis.flushDB();
        jedis.mset("f1", "1", "f2", "2");
        List<String> res = jedis.mget("f1", "f2");
        System.out.println(res);
    }
    public static void test2(Jedis jedis){
        jedis.flushDB();
        jedis.set("key", "01234567");
        String result = jedis.getrange("key", 0, 2);
        System.out.println(result);
        jedis.setrange("key", 1, "aaaa");
        String val = jedis.get("key");
        System.out.println(val);
    }
    private static void test3(Jedis jedis) {
        jedis.flushDB();
        jedis.mset("key1", "111", "key2", "222");
        long res = jedis.append("key1", "aaa");
        String res1 = jedis.get("key1");
        System.out.println(res+" "+res1);

        long key2 = jedis.incr("key2");
        long key3 = jedis.decr("key2");
        System.out.println(key2 + " " + key3);
    }
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("tcp://127.0.0.1:8888");
        try(Jedis jedis = jedisPool.getResource()){
            //test1(jedis);
            //test2(jedis);
            test3(jedis);
        }
    }
}
